<?php
namespace app\api\service\uniapp\goodscart;

use app\api\model\Region;
use app\api\model\ShopYiwu;
use app\api\model\ShopYiwuCart;
use app\api\model\UserStore;
use app\common\controller\Api;
use think\Db;

class GoodsCart extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function loadGoodsCart($user_id,$shop_id){
        //获取用户在该店铺的购物车数据
        $cart = ShopYiwuCart::where(['user_id'=>$user_id,'store_id'=>$shop_id])->select();
        $cartList = array();
        $total_num = 0;
        $total_price = 0;
        foreach ($cart as $k=>$v){
//            $cartList[$v['goods_id']] = [
//                'market_price'=>$v['market_price'],
//                'goods_price'=>$v['goods_price'],
//                'goods_num'=>$v['goods_num'],
//                'total_price'=>$v['total_price']
//            ];
            $cart[$k]['goods_pic'] = config('site_url').$v['goods_pic'];
            $total_num+=$v['goods_num'];
            $total_price= bcadd($total_price,$v['total_price'],2);
        }
        $cartdata['total_num'] = $total_num;
        $cartdata['total_price'] = $total_price;
        $cartdata['cart'] = $cart;
        return $cartdata;
    }
}